package com.example.attempt.service.impl;

import com.example.attempt.entity.Homework;
import com.example.attempt.mapper.HomeworkMapper;
import com.example.attempt.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class HomeworkServiceImpl implements HomeworkService {
    @Autowired
    private HomeworkMapper homeworkMapper;
    @Override
    public int addHomework(Homework homework) {
        System.out.println("tianjia "+homework.toString());
        homeworkMapper.addHomework(homework);
        return 0;
    }

    @Override
    public int getNowHid() {
        if (homeworkMapper.queryAll().size()==0){
            return 1;
        }
        System.out.println(homeworkMapper.getNowHid());
        return homeworkMapper.getNowHid();
    }

    @Override
    public Homework queryByHid(int hid) {
        return homeworkMapper.queryByHid(hid);
    }

    @Override
    public List<Homework> queryByCid(String cid) {
        return homeworkMapper.queryByCid(cid);
    }

    @Override
    public int updateRate(int hid,float stu,float assist,float teacher) {
        homeworkMapper.updateRate(hid,stu,assist,teacher);
        return 0;
    }

    @Override
    public int updateIsDistribute(int hid, int isDistribute){
        homeworkMapper.updateIsDistribute(hid, isDistribute);
        return 0;
    }

    @Override
    public int updateHomework(Homework homework) {
        homeworkMapper.updateHomework(homework);
        return 0;
    }

    @Override
    public int updateIsPublish(int hid, int isPublish) {
        homeworkMapper.updateIsPublish(hid, isPublish);
        return 0;
    }

    @Override
    public int updateIsCheck(int hid, int isCheck){
        homeworkMapper.updateIsCheck(hid, isCheck);
        return 0;
    }

    @Override
    public int setThreshold(int hid, double threshold){
        homeworkMapper.setThreshold(hid, threshold);
        return 0;
    }

    @Override
    public int setLink(String link, int hid) {
        homeworkMapper.setLink(link,hid);
        return 1;
    }
    @Override
    public int updateDtime(LocalDateTime dtime,int hid){
        homeworkMapper.updateDtime(dtime,hid);
        return 1;
    }
    @Override
    public List<Homework> queryByTid(String tid){
        return homeworkMapper.queryByTid(tid);
    }
}
